package cn.itsource.ymcc;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.factory.Factory.Payment;
import com.alipay.easysdk.kernel.Config;
import com.alipay.easysdk.kernel.util.ResponseChecker;
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        // 1. 设置参数（全局只需设置一次）
        Factory.setOptions(getOptions());
        try {
            // 2. 发起API调用（以创建当面付收款二维码为例）

            //String subject  普通订单  标题
            //String outTradeNo   订单编号
            //String totalAmount   金额
            //String returnUrl     回调地址
            AlipayTradePagePayResponse response = Payment.Page()
                    .pay("java课程", "13524615464",
                            "100", "http://www.ymcc.com:6002/list.html?keyword=java");
            // 3. 处理响应或异常
            if (ResponseChecker.success(response)) {
                System.out.println(response.getBody());
                System.out.println("调用成功");
            } else {
                System.err.println("调用失败，原因：" + response);
            }
        } catch (Exception e) {
            System.err.println("调用遭遇异常，原因：" + e.getMessage());
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    private static Config getOptions() {
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi.alipaydev.com";
        config.signType = "RSA2";
        config.appId = "2021000122675584";
        // 为避免私钥随源码泄露，推荐从文件中读取私钥字符串而不是写入源码中
        config.merchantPrivateKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCS40dfjYrldFJ8gd/wh6ZYrUz7f/Gt+hj8SHzkVlT2v8whYblu0dQr2tIIMO2jWuFZLOHn840Rbbpv5e+LXmx0TSeJU3w+EFszeRWDaRreM7JuEzB2L1Jhl8fLefM1f4m5ZN9yzBk4K72WQdHGNWRAiG2ORMcq5NbdaVPw96s40bQTMZfUfb4DN6xviA0c6nqDfjCgq5nbZ0i08snY/FWsSoOR/TQj8LkVf8TCDGQ819zcaEURVZwoMIRI0HR/RTw9C0XDwzgB4B6sLW+d6Mb2mvVItT5Qa7n87MhBamNJ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z0bNUONcVKDO2cEWZAoGBAI2KNr7SENhZPBdXxxDan7vI6BI+37RmKXN2zq8MCrGk0Mxfg/m4oSiMX08lK5W+uZ46zYsQuCazfu1If1pkG122ya1cSXCRRJpbR2DUkVn3CY2iUNPIMPZKag0EVurQxWVobXXxh9F/9/XzOqeunl9mPUirQxAxvZ7rX6Qrxwap";
        //注：证书文件路径支持设置为文件系统中的路径或CLASS_PATH中的路径，优先从文件系统中加载，加载失败后会继续尝试从CLASS_PATH中加载
//        config.merchantCertPath = "<-- 请填写您的应用公钥证书文件路径，例如：/foo/appCertPublicKey_2019051064521003.crt -->";
//        config.alipayCertPath = "<-- 请填写您的支付宝公钥证书文件路径，例如：/foo/alipayCertPublicKey_RSA2.crt -->";
//        config.alipayRootCertPath = "<-- 请填写您的支付宝根证书文件路径，例如：/foo/alipayRootCert.crt -->";
        //注：如果采用非证书模式，则无需赋值上面的三个证书路径，改为赋值如下的支付宝公钥字符串即可
        // config.alipayPublicKey = "<-- 请填写您的支付宝公钥，例如：MIIBIjANBg... -->";
        //可设置异步通知接收服务地址（可选）
//        config.notifyUrl = "http://www.ymcc.com:6002/order.confirm.html?courseId=19&token=TYs7sQbVVgJRtED7";
        //可设置AES密钥，调用AES加解密相关接口时需要（可选）
        config.encryptKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjdeFolHXyE78tkkR18xExX+7IlWfgMGG6t8RCg0AYdiheEPKzJqBo0btV+2Ny9zkTgCZBT+HhF8I+uVpfO1xsvoGbaK/KrNzabV1TYO83t7lGStRR9d8EC/VuuqRXcgcQEjgGcHOg9eCRjr+WniO7dnglppjYjt+drSrXIhze5dpCcU6GBTmgED5BWpDvze3QoooU8DLZ3cO83mEoKqkEjA6g19j1MiJvuklxUYkT1UtaBRtZBtCpiUscdSWNJ+Rbn8grH2eKVPUIDOq8w9NroXU4bEf76SQkd/HuNpD9NoJVR7WMHzKByCmud1Jn1HI9nFeKKF1legZ9KgKpXV2XwIDAQAB";
        return config;
    }
}